<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='保存文章',active='publish',has_sub=''">
<header th:replace="admin/header::headerFragment(${title},${active},${has_sub})"></header>
<link href="/admin/plugins/tagsinput/jquery.tagsinput.css" rel="stylesheet"/>
<link href="/admin/plugins/select2/dist/css/select2-bootstrap.css" rel="stylesheet"/>
<link href="/admin/plugins/toggles/toggles.css" rel="stylesheet"/>

<link href="/admin/plugins/multi-select/0.9.12/css/multi-select.min.css" rel="stylesheet"/>
<link href="/admin/plugins/select2/3.4.8/select2.min.css" rel="stylesheet"/>
<link href="/admin/plugins/mditor/css/mditor.min.css" rel="stylesheet"/>
<link href="/admin/plugins/summernote/0.8.2/summernote.css" rel="stylesheet"/>
<link href="/admin/plugins/dropzone/4.3.0/min/dropzone.min.css" rel="stylesheet"/>
<style rel="stylesheet">
    #tags_tagsinput {
        background-color: #fafafa;
        border: 1px solid #eeeeee;
    }

    #tags_addTag input {
        width: 100%;
    }

    #tags_addTag {
        margin-top: -5px;
    }

    .mditor .editor{
        font-size: 14px;
        font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    }
    .mditor .backdrop, .mditor .textarea, .mditor .viewer{
        font-size: 14px;
    }
    .markdown-body{
        font-size: 14px;
    }
    .note-toolbar {
        text-align: center;
    }

    .note-editor.note-frame {
        border: none;
    }

    .note-editor .note-toolbar {
        background-color: #f5f5f5;
        padding-bottom: 10px;
    }

    .note-toolbar .note-btn-group {
        margin: 0;
    }

    .note-toolbar .note-btn {
        border: none;
    }

    #articleForm #dropzone {
        min-height: 200px;
        background-color: #dbdde0;
        line-height:200px;
        margin-bottom: 10px;
    }
    #articleForm .dropzone {
        border: 1px dashed #8662c6;
        border-radius: 5px;
        background: white;
    }
    #articleForm .dropzone .dz-message {
        font-weight: 400;
    }
    #articleForm .dropzone .dz-message .note {
        font-size: 0.8em;
        font-weight: 200;
        display: block;
        margin-top: 1.4rem;
    }
</style>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">
                            <th:block th:if="${null != contents}">
                                编辑文章
                            </th:block>
                            <th:block th:unless="${null != contents}">
                                发布文章
                            </th:block>
                        </h4>
                    </div>
                    <div class="col-md-12">
                        <!--TODO attach_url-->
                        <input type="hidden" id="attach_url" th:value="${attach_url}" />
                        <form id="articleForm">
                            <input type="hidden" name="categories" id="categories"/>
                            <input type="hidden" name="cid" th:value="${contents!=null and contents.cid!=null}?${contents.cid}: ''" id="cid"/>
                            <input type="hidden" name="status" th:value="${contents!=null and contents.status !=null}?${contents.status}: 'draft'" id="status"/>
                            <input type="hidden" name="allowComment" th:value="${contents!=null and contents.allowComment !=null}?${contents.allowComment}: true" id="allowComment"/>
                            <input type="hidden" name="allowPing" th:value="${contents!=null and contents.allowPing !=null}?${contents.allowPing}: true" id="allowPing"/>
                            <input type="hidden" name="allowFeed" th:value="${contents!=null and contents.allowFeed !=null}?${contents.allowFeed}: true" id="allowFeed"/>
                            <input type="hidden" name="content" id="content-editor"/>
                            <input type="hidden" name="fmtType"  th:value="${contents!=null and contents.fmtType !=null}?${contents.fmtType}: 'markdown'" id="fmtType"/>

                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <input class="form-control" placeholder="请输入文章标题（必须）" name="title" required="required" aria-required="true"
                                       th:value="${contents!=null and contents.title!=null }?${contents.title}: ''"/>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 0 0 10px;">
                                <input class="form-control" placeholder="自定义访问路径，如：my-first-article  默认为文章id" name="slug"
                                       th:value="${contents!=null and contents.slug !=null}?${contents.slug}: ''"/>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <input name="tags" id="tags" type="text" class="form-control" placeholder="请填写文章标签"
                                       th:value="${contents!=null and contents.tags !=null}?${contents.tags}: ''"/>
                            </div>

                            <div class="form-group col-md-6">
                                <select id="multiple-sel" class="select2 form-control" multiple="multiple" data-placeholder="请选择分类...">
                                    <th:block th:if="${null == categories}">
                                        <option value="默认分类" selected="selected">默认分类</option>
                                    </th:block>
                                    <th:block th:unless="${null == categories}">
                                        <th:block th:each="c : ${categories}">
                                            <option th:value="${c.name}" th:text="${c.name}"
                                                    th:selected="${null !=contents and commons.exist_cat(c, contents.categories)}?true:false"></option>
                                        </th:block>
                                    </th:block>
                                </select>
                            </div>
                            <div class="clearfix"></div>

                            <div class="form-group col-xs-12">
                                <div class="pull-right">
                                    <a id="switch-btn" href="javascript:void(0)" class="btn btn-purple btn-sm waves-effect waves-light switch-editor">
                                        <th:block th:if="${contents!=null and contents.fmtType == 'html'}">
                                            切换为Markdown编辑器
                                        </th:block>
                                        <th:block th:unless="${contents!=null and contents.fmtType == 'html'}">
                                            切换为富文本编辑器
                                        </th:block>
                                    </a>
                                </div>
                            </div>

                            <div id="md-container" class="form-group col-md-12">
                                <textarea id="md-editor" th:class="${null != contents and contents.fmtType != 'html'}? hide : ''" th:utext="${contents!=null and contents.content !=null}?${contents.content}: ''"></textarea>
                            </div>
                            <div id="html-container" class="form-group col-md-12">
                                <div class="summernote">
                                    <th:block th:if="${contents!=null and contents.fmtType == 'html'}" th:utext="${contents!=null and contents.content !=null}?${contents.content}: ''">
                                    </th:block>
                                </div>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">开启评论</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and contents.allowComment!=null }?'toggle toggle-success allow-'+${contents.allowComment}:'toggle toggle-success allow-true'"
                                         onclick="allow_comment(this);" th:attr="on=${contents!=null and contents.allowComment!=null }?${contents.allowComment}:true"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">允许Ping</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and contents.allowPing !=null}?'toggle toggle-success allow-'+${contents.allowPing}:'toggle toggle-success allow-true'"
                                         onclick="allow_ping(this);" th:attr="on=${contents!=null and contents.allowPing!=null }?${contents.allowPing}:true"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">允许订阅</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and  contents.allowFeed !=null}?'toggle toggle-success allow-'+${contents.allowFeed}: 'toggle toggle-success allow-true'"
                                         onclick="allow_feed(this);" th:attr="on=${contents!=null and contents.allowFeed!=null }?${contents.allowFeed}:true"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="col-sm-5">添加缩略图</label>
                                <div class="col-sm-7">
                                    <div id="thumb-toggle" class="toggle toggle-success" on="false" th:attr="thumb_url=${contents!=null and contents.thumbImg !=null}?${contents.thumbImg}: ''" onclick="add_thumbimg(this);"></div>
                                </div>
                            </div>

                            <div id="dropzone-container" class="form-group col-md-12 hide">
                                <div class="dropzone dropzone-previews" id="dropzone">
                                    <div class="dz-message">
                                        <p>可以为你的文章添加一张缩略图 ;)</p>
                                    </div>
                                </div>
                                <input type="hidden" name="thumbImg" id="thumbImg"/>
                            </div>

                            <div class="clearfix"></div>

                            <div class="text-right">
                                <a class="btn btn-default waves-effect waves-light" href="/admin/article">返回列表</a>
                                <button type="button" class="btn btn-primary waves-effect waves-light" onclick="subArticle('publish');">
                                    保存文章
                                </button>
                                <button type="button" class="btn btn-warning waves-effect waves-light" onclick="subArticle('draft');">
                                    存为草稿
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>

<script src="/admin/plugins/tagsinput/jquery.tagsinput.min.js"></script>
<script src="/admin/plugins/jquery-multi-select/jquery.quicksearch.js"></script>

<script src="/admin/plugins/mditor/js/mditor.min.js"></script>
<script src="/admin/plugins/wysihtml5/0.3.0/wysihtml5.min.js"></script>
<script src="/admin/plugins/summernote/0.8.2/summernote.min.js"></script>
<script src="/admin/plugins/summernote/0.8.2/lang/summernote-zh-CN.min.js"></script>
<script src="/admin/plugins/multi-select/0.9.12/js/jquery.multi-select.min.js"></script>
<script src="/admin/plugins/select2/3.4.8/select2.min.js"></script>
<script src="/admin/plugins/jquery-toggles/2.0.4/toggles.min.js"></script>
<script src="/admin/plugins/dropzone/4.3.0/min/dropzone.min.js"></script>
<script src="/admin/plugins/to-markdown/3.1.0/to-markdown.min.js"></script>

<script src="/admin/js/article.js" type="text/javascript"></script>
</body>
</html>